'=======================================
' 执行所有测试 case
'=======================================
Private Sub test_ObjStack_ALL_case()
    ' 基础功能测试
    test_ObjStack_base
    ' peek 测试
    test_ObjStack_peek
    ' clear 测试
    test_ObjStack_clear
    ' item 测试
    test_ObjStack_Item
    ' 属性 MaxIndex 测试
    test_ObjStack_MaxIndex
End Sub

' ================================================================
' ================================================================
' ================================================================

' 基础功能测试
Private Sub test_ObjStack_base()
    Dim stack As ObjStack
    Set stack = New ObjStack

    ' 空测试
    Debug.Assert stack.Count = 0
    Debug.Assert stack.pop Is Nothing
    Debug.Assert stack.peek Is Nothing

    ' 插入一个数据并弹出
    Dim v1 As Collection
    Set v1 = New Collection
    stack.push v1
    Debug.Assert stack.Count = 1
    Debug.Assert stack.peek Is v1
    Debug.Assert stack.pop Is v1

    Debug.Assert stack.Count = 0
    Debug.Assert stack.pop Is Nothing
    Debug.Assert stack.peek Is Nothing

    ' 插入两个数据并弹出
    Dim v2 As Collection
    Set v2 = New Collection
    stack.push v1
    stack.push v2
    Debug.Assert stack.Count = 2
    Debug.Assert stack.peek Is v2
    Debug.Assert stack.pop Is v2
    Debug.Assert stack.Count = 1
    Debug.Assert stack.peek Is v1
    Debug.Assert stack.pop Is v1

    Debug.Assert stack.Count = 0
    Debug.Assert stack.pop Is Nothing
    Debug.Assert stack.peek Is Nothing
End Sub

' peek 测试
Private Sub test_ObjStack_peek()
    Dim stack As ObjStack
    Set stack = New ObjStack

    Dim v1 As Collection
    Set v1 = New Collection
    stack.push v1
    Debug.Assert stack.peek Is v1

    Dim v2 As Collection
    Set v2 = New Collection
    stack.push v2
    Debug.Assert stack.peek Is v2
End Sub

' clear 测试
Private Sub test_ObjStack_clear()
    Dim stack As ObjStack
    Set stack = New ObjStack

    Dim v1 As Collection
    Set v1 = New Collection
    Dim v2 As Collection
    Set v2 = New Collection
    Dim v3 As Collection
    Set v3 = New Collection

    stack.push v1
    stack.push v2
    stack.push v3
    Debug.Assert stack.Count = 3

    stack.clear
    Debug.Assert stack.Count = 0

    stack.push v1
    stack.push v2
    stack.push v3
    Debug.Assert stack.Count = 3

    Debug.Assert stack.pop Is v3
    Debug.Assert stack.Count = 2
    Debug.Assert stack.pop Is v2
    Debug.Assert stack.Count = 1
    Debug.Assert stack.pop Is v1
    Debug.Assert stack.Count = 0
    Debug.Assert stack.pop Is Nothing
    Debug.Assert stack.Count = 0

End Sub

' item 测试
Private Sub test_ObjStack_Item()
    Dim stack As ObjStack
    Set stack = New ObjStack

    Dim v1 As Collection
    Set v1 = New Collection
    stack.push v1

    Dim v2 As Collection
    Set v2 = New Collection
    stack.push v2

    Dim v3 As Collection
    Set v3 = New Collection
    stack.push v3

    Debug.Assert stack.Item(0) is v1
    Debug.Assert stack.Item(1) is v2
    Debug.Assert stack.Item(stack.Count() - 1) is v3
End Sub

' 属性 MaxIndex 测试
Private Sub test_ObjStack_MaxIndex()
    Dim stack As ObjStack
    Set stack = New ObjStack

    Debug.Assert stack.MaxIndex = -1

    Dim v1 As Collection
    Set v1 = New Collection
    stack.push v1

    Debug.Assert stack.MaxIndex = 0

    Dim v2 As Collection
    Set v2 = New Collection
    stack.push v2

    Debug.Assert stack.MaxIndex = 1
End Sub